//
//  AppDelegate.m
//  traveing
//
//  Created by Northwan on 15/5/6.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//
//  iOS Dev Account:帐号：yejin@goodigo.cn 密码：whltx@2014
//  接口地址：http://hpzhlyapi.mydoc.io/
//  效果图地址：http://git.oschina.net/oscharles/travel
//  城市列表获取：http://www.juhe.cn/docs/api/id/20/aid/36
//  航班动态查询秘钥：b26f54631404feb9120b8829b0fd6702 接口地址：http://www.juhe.cn/docs/api/id/20 SDK下载地址：http://www.juhe.cn/juhesdk


#import "AppDelegate.h"
#import "CustomTabBarCtrl.h"
#import <BaiduMapAPI/BMapKit.h>
#import "IpaynowPluginApi.h"
#import "NewFeaturesCtrl.h"
@interface AppDelegate ()
{
    BMKMapManager* _mapManager;
}

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //计算缩放比值
    if(SCREENH > 480){
        self.autoSizeScaleX = SCREENW/320;
        self.autoSizeScaleY = SCREENH/568;
    }else{
        self.autoSizeScaleX = 1.0;
        self.autoSizeScaleY = SCREENH/568;
    }
    [self initBaiduMapLocation];
    
    
    //设置整体的导航栏的背影颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    if (iOS8) {
        [[UINavigationBar appearance] setTranslucent:NO];
    }
    
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    
    NSString *key = @"CFBundleVersion";
    //2.1判断是否有保存本地版本号
    NSString *localVersion = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
    if (![localVersion isEqualToString:currentVersion]) {
        [self.window setRootViewController:[[NewFeaturesCtrl alloc] init]];
        //保存最新版本号
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:key];
        //同步
        [[NSUserDefaults standardUserDefaults] synchronize];
    }else{
        [self.window setRootViewController:[[CustomTabBarCtrl alloc] init]];
    }
    [self.window makeKeyAndVisible];
    
    return YES;
}

-(void)initBaiduMapLocation{
    _mapManager = [[BMKMapManager alloc]init];
    // 如果要关注网络及授权验证事件，请设定 generalDelegate参数
    BOOL ret = [_mapManager start:kBaiduMapLocationAppkey  generalDelegate:nil];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
}
//独立客户端回调函数
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    [IpaynowPluginApi handleOpenUrl:url];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
